package teamproject.visualization.calculations;

import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import teamproject.graphEditor.Controller;
import teamproject.graphEditor.Node;
import teamproject.graphEditor.PDEEdge;
import edu.uci.ics.jung.graph.util.Pair;

public class VectorCalc {

	public static float calculateLength(Point3f a, Point3f b) {
		float length;

		float xdist = (float) Math.pow(b.x - a.x, 2);
		float ydist = (float) Math.pow(b.y - a.y, 2);
		float zdist = (float) Math.pow(b.z - a.z, 2);

		float sum = xdist + ydist + zdist;

		length = (float) Math.abs(Math.sqrt(sum));

		return length;
	}

	public static Point3f getDest(Controller control, PDEEdge edge) {
		Point3f result = new Point3f();

		Pair<Node> endpoints = control.getGraph().getEndpoints(edge);
		Node second = endpoints.getSecond();

		result.x = second.getX();
		result.y = 0;
		result.z = second.getY();

		return result;
	}

	public static Vector3f getDirectionalVector(Point3f source, Point3f dest) {
		Vector3f vector = new Vector3f();

		float x = dest.x - source.x;
		float y = dest.y - source.y;
		float z = dest.z - source.z;

		vector.x = x;
		vector.y = y;
		vector.z = z;

		vector.normalize();

		return vector;
	}

	public static Vector3d getDirectionalVectorNotNormalized(Point3f source,
			Point3f dest) {
		Vector3d vector = new Vector3d();

		float x = dest.x - source.x;
		float y = dest.y - source.y;
		float z = dest.z - source.z;

		vector.x = x;
		vector.y = y;
		vector.z = z;

		return vector;
	}

	public static Point3f getSource(Controller control, PDEEdge edge) {
		Point3f result = new Point3f();

		Pair<Node> endpoints = control.getGraph().getEndpoints(edge);
		Node first = endpoints.getFirst();

		result.x = first.getX();
		result.y = 0;
		result.z = first.getY();

		return result;
	}
}
